Skip to content

Fix LTX Video skip_layer_mask device mismatch under mmgp offloading#2015

Open
Jnalley123 wants to merge 1 commit into
deepbeepmeep:mainfrom
Jnalley123:fix/ltx-skip-layer-mask-device
Open

Fix LTX Video skip_layer_mask device mismatch under mmgp offloading#2015
Jnalley123 wants to merge 1 commit into
deepbeepmeep:mainfrom
Jnalley123:fix/ltx-skip-layer-mask-device

Conversation

@Jnalley123

Copy link
Copy Markdown

What

Moves skip_layer_mask to the activations' device at its consumption points in models/ltx_video/models/transformers/attention.py:

  • in AttnProcessor2_0.__call__, at the reshape(batch_size, 1, 1) step — covers the AttentionSkip, AttentionValues, and Residual strategies downstream;
  • in BasicTransformerBlock.forward, at the view(-1, 1, 1) step — covers the TransformerBlock strategy.

Why

Transformer3DModel.create_skip_layer_mask builds the mask with device=self.device. Under mmgp offloading the transformer's parameters live in CPU RAM between calls, so self.device reports cpu and the mask is created there, while activations run on cuda. Any STG generation that actually skips blocks (an all-ones mask is discarded early) crashes with:

File ".../models/ltx_video/models/transformers/attention.py", line 1132, in __call__
  hidden_states_a *= skip_layer_mask
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

Reproduced with LTX Video 0.9.8 13B (ltxv_0.9.8_13B_dev_quanto_bf16_int8.safetensors) on Windows, torch 2.10.0+cu130, mmgp 3.7.6. Fixing at the consumption points (rather than at mask creation) keeps the fix correct wherever mmgp happens to be keeping the weights at the time.

Notes for review

🤖 Generated with Claude Code

create_skip_layer_mask builds the mask on the transformer's device,
which reports cpu while mmgp keeps the weights offloaded to RAM. Any
STG generation that actually skips blocks then crashes with
"Expected all tensors to be on the same device, but found at least
two devices, cuda:0 and cpu!" when the cpu mask meets cuda
activations (seen with LTX Video 0.9.8 13B).

Move the mask to the activations' device at the two consumption
points, covering all four SkipLayerStrategy paths: AttentionSkip,
AttentionValues and Residual via the reshape in AttnProcessor2_0,
and TransformerBlock in BasicTransformerBlock.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant